package com.example.demo.service;

import com.example.demo.entity.Dish;
import com.example.demo.entity.vo.DishVO;
import com.example.demo.mapper.DishMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DishService {

    @Autowired
    private DishMapper dishMapper;

    @Autowired
    private TypeService typeService;

    public List<DishVO> getList(Integer state, String inputValue, String typeName,
                                String priceSort, String gradeSort,Integer pSize, Integer pIndex) {
        return dishMapper.getList(state, inputValue, typeName, priceSort, gradeSort, pSize, pIndex);
    }

    public Integer getCount(Integer state, String inputValue, String typeName,
                                String priceSort, String gradeSort) {
        return dishMapper.getCount(state, inputValue, typeName, priceSort, gradeSort);
    }

    public int add(Dish dish) {
        if (dishMapper.add(dish) == 1) {
            return dish.getId();
        } else {
            return 0;
        }
    }

    public int update(Dish dish) {
        return dishMapper.update(dish);
    }

    public int delete(Integer dishId) {
        Dish dish = new Dish();
        dish.setId(dishId);
        dish.setState(-1);
        return dishMapper.update(dish);
    }

    public List<DishVO> getListByOrderId(Integer orderId, Integer userId) {
        return dishMapper.getListByOrderId(orderId, userId);
    }
}
